import * as Router from 'koa-router';
// import { IRouterContext } from '../core/IRouterContext';
import { IRouterContext } from 'koa-router';
import llService from '../service/LlService';
const motorCtr: Router = require('koa-router')();
motorCtr.prefix('/api')
import loginUtil from './../core/LoginUtils';


/**
 * b2b
 * 领料单查询
 * https://dev.anyomall.com:9443/portal/control/wsif/getPicklistInfo
 * 仓库编码:facilityId : WebStoreWarehouse
 * 领料单号:picklistId (为空时查询所有未完成的领料单)
 * 状态:statusId  (为空时查询未完成的领料单，查询已完成领料单时设置"PICKED")
 * 用户名
 * 密码
 */
motorCtr.post('/motor/getPicklistInfo', async (ctx: IRouterContext, next: any) => {

   console.log(' 领料单查询__________________');
   let authorization :any = ctx.header.authorization;
//    let res = ctx.request.body;
    let rq: any = ctx.request
    let data = rq.body;
   let result = await llService.getPicklistInfo(data,authorization);

   ctx.status = 200;
   ctx.body = result;

   await next()

})

/**
 * 领料单查询详情
 * 仓库编码:facilityId : WebStoreWarehouse
 * 领料单号:picklistId : MP10010
 */
motorCtr.post('/motor/getPicklistInfoById', async (ctx: IRouterContext, next: any) => {

   console.log(' 领料单查询   详情__________________');
   let authorization :any = ctx.header.authorization;
   let rq: any = ctx.request
   let data = rq.body;
   let result = await llService.getPicklistInfoById(data,authorization);

   ctx.status = 200;
   ctx.body = result;

   await next()

})


/**
 * b2b
 * 领料单领料确认
 * https://dev.anyomall.com:9443/portal/control/wsif/updatePicklistInfo
 * 仓库编码:faicilityId
 * 领料单号:picklistId
 * 商品信息:productInfo (List<Map>)
 *      订单号:orderId
 *      订单商品行号:orderItemSeqId
 *      商品编码:productCode
 *      已领数量:pickedQuantity
 * 状态:statusId  (为空表示暂存，领料完成时设置"PICKED")
 * 用户名
 * 密码
 */
motorCtr.post('/motor/updatePicklistInfo', async (ctx: IRouterContext, next: any) => {

   console.log('领料单领料确认__________________');
   let authorization :any = ctx.header.authorization;
   let rq: any = ctx.request
   let data = rq.body;
   let result = await llService.updatePicklistInfo(data,authorization);
   ctx.status = 200;
   ctx.body = result;

   await next()

})

export default motorCtr;